Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@babel/preset-env
Advanced tools
The @babel/preset-env package is a Babel preset that allows you to use the latest JavaScript without needing to micromanage which syntax transforms (and optionally, browser polyfills) are needed by your target environment(s). This is done by using compatibility tables to determine which features need to be transformed or polyfilled. It helps in writing next-gen JavaScript code while ensuring backward compatibility.
Transforming ES2015+ syntax to be ES5 compatible
This code sample shows an ES6 arrow function, which @babel/preset-env can transform into a function expression compatible with ES5 environments.
const arrowFunction = () => console.log('Hello, World!');
Optional configuration for browser or Node.js environment targets
This JSON configuration for Babel specifies which browsers should be supported by the output code, allowing @babel/preset-env to tailor the transformations and polyfills to only what is necessary for those environments.
{
"presets": [
["@babel/preset-env", {
"targets": {
"browsers": ["last 2 versions", "> 1%", "ie >= 11"]
}
}]
]
}
Polyfilling missing features based on the target environment
This code sample uses `Array.from` and `Set`, which may not be available in older environments. @babel/preset-env can include the necessary polyfills for these features when configured with `useBuiltIns: 'usage'`.
Array.from(new Set([1, 2, 3]));
core-js is a modular standard library for JavaScript, which includes polyfills for ECMAScript up to 2021. It's often used in conjunction with Babel to polyfill newer JavaScript features in older environments. Unlike @babel/preset-env, core-js does not handle syntax transformations but focuses on providing polyfills for language features.
esbuild is an extremely fast JavaScript bundler and minifier. It can compile modern JavaScript syntax to older versions for compatibility purposes, similar to what @babel/preset-env does. However, esbuild is more focused on the bundling aspect and aims to be a more comprehensive build tool rather than just a transpiler.
TypeScript is a superset of JavaScript that adds static types. The TypeScript compiler can also downlevel modern JavaScript to older versions, similar to @babel/preset-env. However, TypeScript's primary focus is on type safety and it requires type annotations, whereas @babel/preset-env is purely about compiling newer JavaScript syntax to older versions.
A Babel preset for each environment.
See our website @babel/preset-env for more information or the issues associated with this package.
Using npm:
npm install --save-dev @babel/preset-env
or using yarn:
yarn add @babel/preset-env --dev
v7.26.0 (2024-10-25)
babel-core
, babel-generator
, babel-parser
, babel-plugin-syntax-import-assertions
, babel-plugin-syntax-import-attributes
, babel-preset-env
, babel-standalone
, babel-types
babel-core
babel-compat-data
, babel-plugin-proposal-regexp-modifiers
, babel-plugin-transform-regexp-modifiers
, babel-preset-env
, babel-standalone
babel-parser
startIndex
parser option (@DylanPiercey)babel-generator
, babel-parser
, babel-plugin-syntax-flow
babel-helpers
, babel-preset-typescript
, babel-runtime-corejs3
import()
in rewriteImportExtensions
(@liuxingbaoyu)babel-generator
, babel-parser
@babel/generator
(@nicolo-ribaudo)babel-core
babel-plugin-proposal-json-modules
, babel-plugin-transform-json-modules
, babel-standalone
proposal-json-modules
to transform-json-modules
(@nicolo-ribaudo)babel-code-frame
, babel-highlight
@babel/highlight
in @babel/code-frame
(@nicolo-ribaudo)babel-generator
, babel-parser
, babel-types
kind
to TSModuleDeclaration
(@liuxingbaoyu)babel-helper-module-transforms
, babel-plugin-transform-modules-commonjs
FAQs
A Babel preset for each environment.
The npm package @babel/preset-env receives a total of 4,908,497 weekly downloads. As such, @babel/preset-env popularity was classified as popular.
We found that @babel/preset-env demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.